package com.coocaa.ops.admin.v1.auth.sys;

import com.coocaa.ops.admin.base.controller.MgrBaseController;
import com.coocaa.ops.admin.v1.auth.sys.service.impl.SysAuthorizeServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author bijiahao
 * @date : 2019/3/11.
 * @description: 系统登录相关的 控制器
 *
 */
@RestController
@RequestMapping("/v1")
public class SysLoginController extends MgrBaseController {
    @Autowired
    private SysAuthorizeServiceImpl sysAuthorizeService;

    /**
     * 登录
     *
     * @param request
     * @param response
     * @return
     * @throws Exception
     */
    @RequestMapping(value = "userlogin",method = {RequestMethod.GET,RequestMethod.POST}, produces = "text/html;charset=UTF-8")
    public String login(HttpServletRequest request, HttpServletResponse response) throws Exception {
        Map result = sysAuthorizeService.userLogin(request, response);
        return render2Json(result);
    }


    @RequestMapping(value = "logout",method = {RequestMethod.GET,RequestMethod.POST})
    public void logout(HttpServletRequest request, HttpServletResponse response) throws Exception {
        sysAuthorizeService.logout(request, response);
    }

    @RequestMapping(value = "/getEnvironment",method = {RequestMethod.GET,RequestMethod.POST})
    public String getEnvironment(HttpServletRequest request){
        Map result = sysAuthorizeService.getEnvironment(request);
        return render2Json(result);
    }


}
